
const { query } = require('../../config/mysqlPool')

const sqlInitUpd = 'update loan set'
const qTable = 'select * from loan', orderBy = 'order by create_time', limit = 'desc limit ?,?'
exports.findApproveById = id => query(`${qTable} where id = ?`, [id])
exports.updateApproveById = row => query(`${sqlInitUpd} status=?  where id = ?`, [row.status, row.id])

exports.findApproveList = (limitA, limitB, fields) => {
  const keys = Object.keys(fields)
  const values = Object.values(fields)
  return query(`${qTable} where ${keys.join('=? and ')}=? ${orderBy} ${limit}`, [...values, limitA, limitB])
}
exports.getApproveCountByFields = (fields) => {
  const keys = Object.keys(fields)
  const values = Object.values(fields)
  return query(`select count(*) as total from loan where ${keys.join('=? and ')}=?`, [...values])
}